import pytest
from utils.utils import *
import allure
from faker import Faker
faker = Faker(locale='zh_cn')
name = faker.name()
@allure.story("新增用户分组")
def test_AddGroupName():
    reset_token()
    add_group_step = requests_send("新增用户分组",
                  "post",
                  "/adminapi/user/user_group/save.html"
                  ,{"group_name":str(name)}).validate().\
                    assert_equal("status_code",200).\
                    assert_equal("body.msg","提交成功")
    step_run_AddGroup = Step_Obj(add_group_step)
    last_response = start_api([step_run_AddGroup,])
    """
        last_response = {'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiIxZDg0OTY3ZTRhZmIwNmU3MTkwYjMzNmNiZDcyZGE4ZiIsImlzcyI6IjEyMS40MC44Ni40IiwiYXVkIjoiMTIxLjQwLjg2LjQiLCJpYXQiOjE3NDQ3ODgxNDksIm5iZiI6MTc0NDc4ODE0OSwiZXhwI
        joxNzQ3MzgwMTQ5LCJqdGkiOnsiaWQiOjEsInR5cGUiOiJhZG1pbiJ9fQ.zWHCn9s4GMc0L_5DzKOPrYETjszQiJV7spHKFA0G_KA', 'res_data': {'status': 200, 'msg': '提交成功', 'code': '100017'}}
    """
    # # 提取msg怎么取？
    # print(last_response['res_data']['msg'])
    # # 提取code？
    # print(last_response['res_data']['code'])
@allure.story("删除用户分组")
def test_DeleteGruopName():
    reset_token()
    search_group_step = requests_send("查询用户分组",
                                      "get",
                                      "/adminapi/user/user_group/list?page=1&limit=15"
                                      ).validate(). \
        assert_equal("status_code", 200). \
        assert_equal("body.msg", "success")
    last_response = start_api([search_group_step, ])
    list_group = last_response['res_data']['data']['list']
    for obj in list_group:
        if obj['group_name'] == str(name):
            id = obj['id']
    delete_group_step = requests_send("删除用户分组",
                                   "delete",
                                   "/adminapi/user/user_group/del/"+str(id)
                                   ).validate(). \
        assert_equal("status_code", 200). \
        assert_equal("body.msg", "删除成功!")
    step_run_DeleteGroup = Step_Obj(delete_group_step)
    last_response = start_api([step_run_DeleteGroup, ])


if __name__ == '__main__':
    pytest.main()







